package com.nami.conver.domain.handler.impl;


import com.nami.conver.domain.pchat.model.ConverModel;
import com.nami.conver.domain.pchat.service.ConverTaskService;
import com.nami.conver.domain.repository.CacheConverRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class StoreConverTaskServiceImpl extends AbstractConverSyncHandler {

    @Autowired
    public StoreConverTaskServiceImpl(CacheConverRepository cacheConverRepository,
                                      ConverTaskService taskService) {
        super(cacheConverRepository, taskService);
    }

    @Override
    public void doHandler(String key) {
        Boolean ifPresent = TASK_CACHE.getIfPresent(key);
        if (null == ifPresent) {
            TASK_CACHE.put(key, Boolean.TRUE);
        }
    }

    @Override
    public boolean writeNow(String key) {
        ConverModel conver = cacheConverRepository.get(key);
        if (conver == null) {
            log.warn("[conver] 同步会话出现错误，找不到会话，key={}", key);
            return false;
        }
        cacheConverRepository.writeConver(conver);
        converTaskService.addAsyncWriteConverTask(buildTaskKey(conver));
        return Boolean.TRUE;
    }

//    @Resource
//    public StoreConverTaskServiceImpl(RemoteConverService converService) {
//        super(converService);
//        this.converService = converService;
//    }


}

